package com.focusai.efairy.ui.adapter.dev;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.model.dev.DeviceDetailInfo;
import com.focusai.efairy.utils.Constants;
import com.focusai.efairy.utils.DecimalUtils;
import com.focusai.efairy.utils.StrByCodeUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by Luogw on 2017/8/22.
 */

public class DeviceInfoViewBinder extends ItemViewBinder<DeviceDetailInfo, DeviceInfoViewBinder.ViewHolder> {

    private Context mContext;

    public DeviceInfoViewBinder(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_dev_info, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull DeviceDetailInfo deviceInfo) {
        holder.tvDevName.setText(deviceInfo.efairydevice_name);
        holder.tvDevUnit.setText(deviceInfo.efairydevice_project_name);
        holder.tvDevId.setText(deviceInfo.efairydevice_id + "");
        holder.tvDevMainCode.setText(DeviceDetailInfo.getMainCode(deviceInfo.efairydevice_uuid));
        holder.tvDevSecondCode.setText(DeviceDetailInfo.getsecodeCode(deviceInfo.efairydevice_uuid));
        holder.tvDevInstallDate.setText(deviceInfo.efairydevice_install_time);
        holder.tvDevInstallAddress.setText(deviceInfo.efairydevice_address);
//        holder.tvDevElectricity.setText(deviceInfo.efairydevice_name);
//        holder.tvDevCommStatus.setText(StrByCodeUtils.getStatusByDevState(deviceInfo.efairydevice_state));
        holder.tvDevWarrningtatus.setTextColor(mContext.getResources().getColor(StrByCodeUtils.getColorByDevState(deviceInfo.efairydevice_alarm_id)));
        holder.tvDevWarrningtatus.setText(StrByCodeUtils.getStatusByDevState(deviceInfo.efairydevice_alarm_id));
        holder.tvDevSofeVersion.setText(deviceInfo.efairydevice_version_date + DecimalUtils.formatNum(deviceInfo.efairydevice_version));

        if (deviceInfo.efairydevice_is_online == Constants.DEVICE_IS_ONLINE){
            holder.tvWirelessStatus.setText(R.string.online);
        }else {
            holder.tvWirelessStatus.setText(R.string.unline);
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
         TextView tvDevName;
         TextView tvDevUnit;
         TextView tvDevId;
         TextView tvDevMainCode;
         TextView tvDevSecondCode;
         TextView tvDevSofeVersion;
         TextView tvDevInstallDate;
         TextView tvDevInstallAddress;
         TextView tvDevElectricity;
         TextView tvWirelessStatus;
         TextView tvDevCommStatus;
         TextView tvDevWarrningtatus;

        ViewHolder(View itemView) {
            super(itemView);
            tvDevName = (TextView) itemView.findViewById(R.id.tv_dev_name);
            tvDevUnit = (TextView) itemView.findViewById(R.id.tv_dev_unit);
            tvDevId = (TextView) itemView.findViewById(R.id.tv_dev_id);
            tvDevSofeVersion = (TextView) itemView.findViewById(R.id.tv_dev_sofe_version);
            tvDevInstallDate = (TextView) itemView.findViewById(R.id.tv_dev_install_data);
            tvDevInstallAddress = (TextView) itemView.findViewById(R.id.tv_dev_install_address);
            tvDevMainCode = (TextView) itemView.findViewById(R.id.tv_dev_main_code);
            tvDevSecondCode = (TextView) itemView.findViewById(R.id.tv_dev_second_code);
            tvDevElectricity = (TextView) itemView.findViewById(R.id.tv_dev_electricity);
            tvWirelessStatus = (TextView) itemView.findViewById(R.id.tv_wireless_comm_status);
            tvDevCommStatus = (TextView) itemView.findViewById(R.id.tv_dev_comm_status);
            tvDevWarrningtatus = (TextView) itemView.findViewById(R.id.tv_dev_warnning_status);
        }

    }
}

